package com.atguigu.realtime.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @Author lzc
 * @Date 2022/7/28 14:28
 */
public class RedisUtil {
    
    private static JedisPool pool;
    
    static {
        JedisPoolConfig config = new JedisPoolConfig();
        config.setMaxTotal(100);
        config.setMaxIdle(20);  //允许的最大空闲数
        config.setMinIdle(2);
        
        config.setMaxWaitMillis(10 * 1000);//最大等待时间
        config.setTestOnCreate(true);
        config.setTestOnBorrow(true);
        config.setTestOnReturn(true);
    
        pool = new JedisPool(config, "hadoop162");
    }
    
    
    public static Jedis getRedisClient() {
    
        Jedis jedis = pool.getResource();
        jedis.select(1);  // 获取的客户端默认都选择1号库
        return jedis;
    }
}
